package com.lapelittle.framework.model.page;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "分页请求参数")
public class PageRequest {
    
    @Schema(description = "页码(从1开始)")
    private Integer pageNum = 1;
    
    @Schema(description = "每页数量")
    private Integer pageSize = 10;
    
    @Schema(description = "排序字段")
    private String orderBy;
    
    @Schema(description = "排序方式(asc/desc)")
    private String orderType;

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum < 1 ? 1 : pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize < 1 ? 10 : pageSize;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public String getOrderType() {
        return orderType;
    }

    public void setOrderType(String orderType) {
        this.orderType = orderType;
    }
    
    /**
     * 获取开始位置
     */
    public Integer getOffset() {
        return (pageNum - 1) * pageSize;
    }
}